package org.example.leetCode;

/**
 * @Author Qinkai
 * @Description TODO $
 * @Date $ 2021-09-22$
 * @Param $
 * @return $
 **/
public class CompareVersion {
    public int compareVersion(String version1, String version2) {
        String[] s1 = version1.split("\\.");
        String[] s2 = version2.split("\\.");

        for (int i = 0; i < Math.max(s1.length, s2.length); i++) {
            int m = i < s1.length ? Integer.parseInt(s1[i]) : 0;
            int n = i < s2.length ? Integer.parseInt(s2[i]) : 0;

            if (m < n) {
                return -1;
            } else if (m > n) {
                return 1;
            }

        }
        return 0;
    }
}
